<?php
	//VARIABLE DECLARATION
	$maxWidth = 80;
	$maxHeight = 80;

	$_GET['i'] = "../Recourse/".$_GET['i'];
	$ImageData = getimagesize($_GET['i']);
	switch($ImageData['mime']) {
		case 'image/jpeg':
		case 'image/pjpeg':
			$ext = '.jpg';
			break;
		case 'image/gif':
			$ext = '.gif';
			break;
		case 'image/png':
		case 'image/x-png':
			$ext = '.png';
			break;
		default:
			imagejpeg(imagecreate(0, 0));
			exit;
	}
	
	header("Content-type: ".$ImageData['mime']);
	switch($ext) {
		case '.jpg':
			$MyImage = imagecreatefromjpeg($_GET['i']);
			break;
		case '.gif':
			$MyImage = imagecreatefromgif($_GET['i']);
			break;
		case '.png':
			$MyImage = imagecreatefrompng($_GET['i']);
			break;
	}
	
	if($ImageData[0] > $maxWidth) { //Too large, resize and save
		$Ratio = $maxWidth*100/$ImageData[0];
		$NewHeight = $Ratio*$ImageData[1]/100;
		$MyNewImage = imagecreatetruecolor($maxWidth, $NewHeight);
		imagecopyresized($MyNewImage, $MyImage,0,0,0,0,$maxWidth,$NewHeight,$ImageData[0],$ImageData[1]);
		imagedestroy($MyImage);
		$MyImage = $MyNewImage;
		$ImageData[1] = $NewHeight;
		$ImageData[0] = $maxWidth;
	}
	
	if($ImageData[1] > $maxHeight) { //Too large, resize and save
		$Ratio = $maxHeight*100/$ImageData[1];
		$NewWidth = $Ratio*$ImageData[0]/100;
		$MyNewImage = imagecreatetruecolor($NewWidth, $maxHeight);
		imagecopyresized($MyNewImage, $MyImage,0,0,0,0,$NewWidth,$maxHeight,$ImageData[0],$ImageData[1]);
		imagedestroy($MyImage);
		$MyImage = $MyNewImage;
		$ImageData[1] = $maxHeight;
		$ImageData[0] = $NewWidth;
	}
	
	switch($ext) {
		case '.jpg':
    		imagejpeg($MyImage);
			break;
		case '.gif':
			imagegif($MyImage);
			break;
		case '.png':
			imagepng($MyImage);
			break;
	}
	
	imagedestroy($MyImage);
	imagedestroy($MyNewImage);	
?>